package datastructure.stack;

import datastructure.list.ArrayListHighPerformance;
import datastructure.list.List;

/**
 * DESCRIPTION: 栈
 * 先进后出
 * Author: ammar
 * Date:   2021/12/15
 * Time:   上午8:36
 */
public class Stack<E> {
    private List<E> list = new ArrayListHighPerformance<>();

    public void clear() {
        list.clear();
    }
    /**
     * 元素数量
     * @return
     */
    public int size() {
        return list.size();
    }

    /**
     * 是否为空
     * @return
     */
    public boolean isEmpty() {
        return list.isEmpty();
    }

    /**
     * 入栈
     * @param element
     */
    public void push(E element) {
        list.add(element);
    }

    /**
     * 出栈
     * @return
     */
    public E pop() {
        return list.remove(list.size() - 1);
    }

    /**
     * 获取栈顶元素
     * @return
     */
    public E top() {
        return list.get(list.size() - 1);
    }
}
